<?php
use yii\widgets\Pjax;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\Modal;
//var_dump($dataProvider);
$gridColumns = [
    ['class' => 'yii\grid\SerialColumn'],
    'id',
    'thread_id',
    'user_id',
    'user_name',
    'title',
    [
        'format' => 'html',
        'attribute' => 'user_name',
        'label'=>'Image',
        'headerOptions' => ['width' => '80%',],
    ],

    [   'class' => 'yii\grid\ActionColumn',
        'template' => '{view} {delete}',
        // 'headerOptions' => ['width' => '20%', 'class' => 'activity-view-link',],
        'headerOptions' => ['width' => '20%',],
        'contentOptions' => ['class' => 'padding-left-5px'],

        'buttons' => [
            'view' => function ($url, $model, $key) {
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>',$url, [
                    // 'id' => 'activity-view-link',
                    'class' => 'activity-view-link',
                    'title' => Yii::t('yii', '查看元素'),
                    'data-toggle' => 'modal',
                    'data-target' => '#activity-modal',
                    'data-id' => $key,
                    'data-pjax' => '0',

                ]);
            },
        ],


    ],

];
?>


<?php

// Pjax::begin();

// echo kartik\grid\GridView::widget([
echo yii\grid\GridView::widget([
    'dataProvider' => $dataProvider,
    'columns'=>$gridColumns,
    'summary'=>false,
    // 'responsive'=>true,
    // 'hover'=>true
]);
// Pjax::end();

?>


<?php
$requestUrl = Url::toRoute('view-ajax');
$this->registerJs(
    // "$('.activity-view-link').click(function() {
    "$('.activity-view-link').click(function() {
    $.get(
        '{$requestUrl}',
        {
            id: $(this).closest('tr').data('key')
        },
        function (data) {
            $('.modal-body').html(data);
            $('#activity-modal').modal();
        }
    );
});
    "
); ?>


<?php Modal::begin([
    'id' => 'activity-modal',
    'header' => '<h4 class="modal-title">View Image</h4>',
    'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',

]); ?>

<!-- <div class="well">


</div> -->


<?php Modal::end(); ?>
